package cn.com.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import cn.com.entity.YiSheng;

public class YiShengDao {
	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	Session session;
	Transaction transaction;
	public boolean yiShengLogin(String uname,String upwd){
		boolean b=false;
		session=sessionFactory.openSession();
		String hql="from YiSheng where uname=? and upwd=?";
		Query query=session.createQuery(hql);
		query.setString(0, uname);
		query.setString(1, upwd);
		List<YiSheng> list=query.list();
		if(list.size()==1){
			b=true;
		}
		session.close();
		return b;
	}
	public List<YiSheng> chakanyisheng(){
		session=sessionFactory.openSession();
		String hql="from YiSheng";
		Query query=session.createQuery(hql);
		List<YiSheng> yslist=query.list();
		return yslist;
	}
	public boolean insertyisheng(int yishengid,int keshiid,String name){
		boolean b=false;
		session=sessionFactory.openSession();
		YiSheng yisheng=new YiSheng();
		yisheng.setYishengid(yishengid);
		yisheng.setKeshiid(keshiid);
		yisheng.setName(name);
		transaction=session.beginTransaction();
		if(yisheng!=null){
			session.save(yisheng);
			transaction.commit();
			session.close();
		}
		return b;
	}
	
}
